'use strict';

app.controller('falsereportCtrl', function ($rootScope, $scope, $http) {

    // console.log("falsereport");
   //  $scope.falsereportImages = [
   //     {
   //     		"id":"0",
   //     		"url":"/assets/img/picture1/pic1.jpg"
   //     },
   //     {
   //     		"id":"1",
   //     		"url":"/assets/img/picture1/pic2.jpg"
  	// 	},
  	// 	{
  	// 		"id":"2",
  	// 		"url":"/assets/img/picture1/pic3.jpg"
  	// 	},
  	// 	{
   //     		"id": "3",
   //     		"url":"/assets/img/picture1/pic4.jpg"
   //      },
   //      {
   //     		"id":"4",
   //     		"url":"/assets/img/picture1/pic5.jpg"
  	// 	},
   //  	{
   //  		"id":"5",
   //  		"url":"/assets/img/picture1/pic6.jpg"
   //  	},
   //      {
   //          "id":"6",
   //          "url":"/assets/img/picture1/pic7.jpg"
   //      },
   //      {
   //          "id":"7",
   //          "url":"/assets/img/picture1/pic8.jpg"
   //      },
   //      {
   //          "id":"8",
   //          "url":"/assets/img/picture1/pic9.jpg"
   //      },
   //      {
   //          "id":"9",
   //          "url":"/assets/img/picture1/pic10.jpg"
   //      }
  	// ];
  	//console.log($scope.falsereportImages);

    //获取误报图片接口
    $http.get('/api/getFalseImage').then(function(response){
      console.log("FalseImage");
      if(response.status==200){
        // console.log(response);
        $scope.falseImages = response.data.image;
        console.log($scope.falseImages.length);
        for (var i = 0; i < $scope.falseImages.length; i++) {
          $scope.falseImages[i].num = i;
        }
        console.log($scope.falseImages);
      }
      else{
        console.log(response.status);
      }
    });
    var onload = function (){
    var year=new Date().getFullYear(); //获取当前年份
         
    var sel1 = document.getElementById ('sel1');//获取select下拉列表
    var sel2 = document.getElementById ('sel2');//获取select下拉列表
    var sel3 = document.getElementById ('sel3');//获取select下拉列表
    var sel4 = document.getElementById ('sel4');//获取select下拉列表
    var sel5 = document.getElementById ('sel5');//获取select下拉列表
    // var sel6 = document.getElementById ('sel6');//获取select下拉列表
    var sel7 = document.getElementById ('sel7');//获取select下拉列表
    var sel8 = document.getElementById ('sel8');//获取select下拉列表
    // var sel9 = document.getElementById ('sel9');//获取select下拉列表
    //对年份的选择的下拉框内容进行设置
    for ( var i = 2010; i < year+3; i++)//循环添加2018到当前年份加3年的每个年份依次添加到下拉列表
    {
       var option = document.createElement ('option');
       option.value = i;
       var txt = document.createTextNode (i);
       option.appendChild (txt);
       sel1.appendChild (option); 
       
    }
    //对月份选择的下拉框内容进行设置
    for( var i = 1; i < 13; i++){
        var option = document.createElement ('option');
        option.value = i;
        var txt = document.createTextNode (i);
        option.appendChild (txt);
        sel2.appendChild (option);
    }
    //对日选择的下拉框内容进行设置
    for( var i = 1; i <= 31; i++){
        var option = document.createElement ('option');
        option.value = i;
        var txt = document.createTextNode (i);
        option.appendChild (txt);
        sel3.appendChild (option);
    }
    for ( var i = 0; i < 24; i++)
    {
       var option = document.createElement ('option');
       option.value = i;
       var txt = document.createTextNode (i);
       option.appendChild (txt);
       sel4.appendChild (option);
    }
    for( var i = 0; i< 60; i++){
        var option = document.createElement ('option');
        option.value = i;
        var txt = document.createTextNode (i);
        option.appendChild (txt);
        sel5.appendChild (option);
    }
    // for( var i = 0; i < 60; i++){
    //     var option = document.createElement ('option');
    //     option.value = i;
    //     var txt = document.createTextNode (i);
    //     option.appendChild (txt);
    //     sel6.appendChild (option);
    // }
     for ( var i = 0; i < 24; i++)
    {
       var option = document.createElement ('option');
       option.value = i;
       var txt = document.createTextNode (i);
       option.appendChild (txt);
       sel7.appendChild (option);
    }
    for( var i = 0; i< 60; i++){
        var option = document.createElement ('option');
        option.value = i;
        var txt = document.createTextNode (i);
        option.appendChild (txt);
        sel8.appendChild (option);
    }
    // for( var i = 0; i < 60; i++){
    //     var option = document.createElement ('option');
    //     option.value = i;
    //     var txt = document.createTextNode (i);
    //     option.appendChild (txt);
    //     sel9.appendChild (option);
    // }

    $scope.year = 0;
    $scope.month = 0;
    $scope.day = 0;
    $scope.hour1 = 0;
    $scope.minute1 = 0;
    $scope.second1 = 0;
    $scope.hour2 = 0;
    $scope.minute2 = 0;
    $scope.second2 = 0;

    $scope.changeYear = function(data){
        // console.log(data);
        $scope.year = data;
        // console.log($scope.year);
    }
    $scope.changeMonth = function(data){
        // console.log(data);
        $scope.month = data;
        // console.log($scope.month);
    }
    $scope.changeDay = function(data){
        // console.log(data);
        $scope.day = data;
        // console.log($scope.day);
    }
    $scope.changeHour1 = function(data){
        // console.log(data);
        $scope.hour1 = data;
        // console.log($scope.hour1);
    }
    $scope.changeMinute1 = function(data){
        // console.log(data);
        $scope.minute1 = data;
        // console.log($scope.minute1);
    }
    $scope.changeSecond1 = function(data){
        // console.log(data);
        $scope.second1 = data;
        // console.log($scope.second1);
    }
    $scope.changeHour2 = function(data){
        // console.log(data);
        $scope.hour2 = data;
    }
    $scope.changeMinute2 = function(data){
        // console.log(data);
        $scope.minute2 = data;
    }
    $scope.changeSecond2 = function(data){
        // console.log(data);
        $scope.second2 = data;
    }
    
  }
  onload();
  $scope.alarmSubmit = function (){
    var year,month,day,hoursta,minsta,secondsta,hourend,minend,secondend = "";
    year = $scope.year;
    if($scope.month < 10){//如果月份小于10，则显示的时候前面补0
        month = '0' + $scope.month;
    }else{
        month = $scope.month;
    }
    if($scope.day < 10){//如果日份小于10，则显示的时候前面补0
        day = '0' + $scope.day;
    }else{
        day = $scope.day;
    }
    if($scope.hour1<10){
        hoursta = '0' + $scope.hour1;
    }else{
        hoursta = $scope.hour1;
    }
    if($scope.minute1<10){
        minsta = '0' + $scope.minute1;
    }else{
        minsta = $scope.minute1;
    }
    if($scope.second1<10){
        secondsta = '0' + $scope.second1;
    }else{
        secondsta = $scope.second1;
    }
    if($scope.hour2<10){
        hourend = '0' + $scope.hour2;
    }else{
        hourend = $scope.hour2;
    }
    if($scope.minute2<10){
        minend = '0' + $scope.minute2;
    }else{
        minend = $scope.minute2;
    }
    if($scope.second2<10){
        secondend = '0' + $scope.second2;
    }else{
        secondend = $scope.second2;
    }

    $scope.imgTime = {
        "date":"",
        "timeStart":"",
        "timeEnd":""
    };
    //对所选日期格式进行拼接
     $scope.imgTime.date = year + month + day;
    //对所选起始时间进行拼接
     $scope.imgTime.timeStart = hoursta + ':' + minsta + ':' + secondsta;
    //对所选结束时间进行拼接
     $scope.imgTime.timeEnd = hourend + ':' + minend + ':' + secondend;
    console.log($scope.imgTime);
    
    var timeData = $scope.imgTime;
    $http.get('/api/searchFalseImage',{params:{"date":timeData.date,"timeStart":timeData.timeStart,"timeEnd":timeData.timeEnd}}).then(function(response){
        if(response.status == 200){
            console.log(response);
            $scope.falseImages = response.data.image;//显示更新后的图片
        }
        else{
          console.log(response.status);
          console.log(response.data);
        }
    });
  }

    $scope.fullImg = function (url,num){
      $scope.fullImage1 = url;
      console.log(num);
      //获取url的图片中包含的类型信息
      for(var i = 0;i < $scope.falseImages.length;i ++){
        if($scope.falseImages[i].url == $scope.fullImage1){
          $scope.falseImageGoods = $scope.falseImages[i].goods;
        }
        // $scope.index = i;
      }
      
    }
    // $scope.index = 0;
    $scope.imagesNum = 1;

    $scope.preFalseImage = function (){
      for(var i=0;i<$scope.falseImages.length;i++){
        if($scope.falseImages[i].url==$scope.fullImage1){
          if(i-1<0){
            //$scope.fullImage1=$scope.falseImages[length-1].url;
            alert("第一张！");
            break;
          }
          else{
            console.log(i-1);
           $scope.fullImage1=$scope.falseImages[i-1].url; 
           $scope.falseImageGoods = $scope.falseImages[i-1].goods;
           break;
          }
          
        }
      }
    }
    $scope.nextFalseImage = function () {
      for(var i=0;i<$scope.falseImages.length;i++){
        if($scope.falseImages[i].url==$scope.fullImage1){
          if(i+1>=$scope.falseImages.length){
            //$scope.fullImage1=$scope.falseImages[0].url;
            alert("最后一张！");
            break;
          }
          else{
            console.log(i+1);
            $scope.fullImage1=$scope.falseImages[i+1].url;
            $scope.falseImageGoods = $scope.falseImages[i+1].goods;
            break;
          }
          
        }
      }
    }

    // $scope.$watch('index',function () {
        
    // $scope.imagesNum = $scope.index+1;

    // },true);


  	// $scope.index = 0;
  	// $scope.imagesNum = 1;
  	// $scope.showImage = $scope.falsereportImages[$scope.index];//显示图片数组里面第一张图片


  	// $scope.pre = function () {
  	// 	$scope.index --;
  	// 	if($scope.index < 0){
  			
  	// 		alert("这是第一张！！！");
   //          $scope.index = $scope.falsereportImages.length-1;
            
	  //   }
	  //   $scope.showImage=$scope.falsereportImages[$scope.index];
		 //   //console.log("aaaaaa");
  	// }
  	
  	// $scope.next = function () {
  	// 	$scope.index ++;
  	// 	if($scope.index == $scope.falsereportImages.length){
   //          $scope.index = 0;
	  //   }
	  //   $scope.showImage=$scope.falsereportImages[$scope.index];
  	// }

  	// $scope.$watch('index',function () {
        
 		// $scope.imagesNum = $scope.index+1;

   //  },true);
   
});



// var picArr=new Array(
//      	"/assets/img/picture1/pic1.jpg",
//      	"/assets/img/picture1/pic2.jpg",
//      	"/assets/img/picture1/pic3.jpg",
//      	"/assets/img/picture1/pic4.jpg",
//      	"/assets/img/picture1/pic5.jpg"
//      );

//     var index=0;
    
//     function next(){
//         index++;
//         if(index==picArr.length){
//             index=0;
//         }
//         document.getElementById("pic").src=picArr[index];
//     };

//     function pre(){
//         index--;
//         if(index<0){
//             index=picArr.length-1;
//         }
//         document.getElementById("pic").src=picArr[index];
//     };


